package com.sibu.yx.promotion.web;


import java.util.Arrays;

import org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import com.sibu.yx.promotion.persistence.config.AppConfig;

import lombok.extern.slf4j.Slf4j;


/**
 * @author yuwenbo
 * @create 2019-04-01 16:37
 **/
@Slf4j
@SpringBootApplication(
        scanBasePackages =
                {"com.sibu.yx.promotion.service",
                "com.sibu.yx.promotion.persistence",
               "com.sibu.yx.promotion.web.support"},
        exclude = {DataSourceAutoConfiguration.class, SpringBootConfiguration.class})
@EnableTransactionManagement
public class ApiWebApplication {

    public static void main(String[] args) {
        SpringApplication springApplication=new SpringApplication(ApiWebApplication.class);
        springApplication.setBannerMode(Banner.Mode.CONSOLE);
        ConfigurableApplicationContext ctx =springApplication.run(args);
        if ("true".equalsIgnoreCase(ctx.getEnvironment().getProperty("debug"))) {
            StringBuilder allBeanNameStr = new StringBuilder(500);
            allBeanNameStr.append("----------------- spring beans ------------------------\n");
            String[] beanNames = ctx.getBeanDefinitionNames();
            allBeanNameStr.append("beanNames 总数：" + beanNames.length + "\n");
            Arrays.sort(beanNames);
            for (String bn : beanNames) {
                allBeanNameStr.append(bn + "\n");
            }
            allBeanNameStr.append("------------------ end -----------------------");
            System.out.println(allBeanNameStr.toString());
            log.info("当前环境为:{}", AppConfig.getInstance().getEnvironmentName());
        }
    }


}
